/**
 * Created by no1 on 2015/8/6.
 */
'use strict';

let DaoBase = require('./DaoBase');
let db = require('./models');
let D = require('./function');
let F = require('../../function');

var util = require("util");

function OrderPayWayDao(data) {
    data = data || {}
    data.model = data.model || db.orderPayWay;
    DaoBase.call(this, data);
}

util.inherits(OrderPayWayDao, DaoBase);

/*
 *@todo 查询
 *@param  {Object}  query  查询的内容
 *@param  {Object}  opt    其他参数
 */

OrderPayWayDao.prototype.getByQuery = function*(query, opt) {

    let ret = yield  this.model.findAll({where: query});
    if (!ret) return F.returnData(1, '查询失败');
    return F.returnData(0, '查询成功.', ret)
};


/*
 *@todo 查询一条 并保存
 *@param  {Object}  query  查询的内容
 *@param  {Object}  opt    其他参数
 */
OrderPayWayDao.prototype.findAndSave = function* (doc, opt) {
    let ret = this.getOneByQuery({orderid: doc.orderid});
    if (ret.error == 1) return F.returnData(1, ret.msg, ret.data);
    //let result = yield this.save(doc);
    return F.returnData(0, result.msg, result.data);
};


module.exports = OrderPayWayDao;